package bo;

import java.sql.*;

public class DBConnection {
	private static String driverName="com.mysql.jdbc.Driver";
	private static String userName="root";
	private static String userPwd="666666";
	private static String dbName="card";
	public static Connection getDBConnection() {
		String url1="jdbc:mysql://localhost:3306/"+dbName;
	    String url2="?user="+userName+"&password="+userPwd;
	    String url3="&useUnicode=true&characterEncoding=UTF-8&useSSL=false";
	    String url=url1+url2+url3;
		try {
			Class.forName(driverName);
			Connection conn=DriverManager.getConnection(url);
			return conn;
		}catch(Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	public static void free(Connection conn,PreparedStatement pstmt,ResultSet rs) {
		try {
			if(rs!=null) {
				rs.close();
			}
			if(pstmt!=null) {
				pstmt.close();
			}
			if(conn!=null) {
				conn.close();
			}
		}catch(SQLException e) {
			e.printStackTrace();
		}
	}

}
